class Codec:
    long_short_map = {}
    long_url_list = []
    index = 0
    prefix = 'http://vtamins.com/'

    def encode(self, longUrl):
        """Encodes a URL to a shortened URL.

        :type longUrl: str
        :rtype: str
        """
        if longUrl in self.long_short_map:
            return self.long_short_map[longUrl]
        shortUrl = self.prefix + str(self.index)
        self.index += 1
        self.long_short_map[longUrl] = shortUrl
        self.long_url_list.append(longUrl)
        return shortUrl

    def decode(self, shortUrl):
        """Decodes a shortened URL to its original URL.

        :type shortUrl: str
        :rtype: str
        """

        index = int(shortUrl.split('/')[-1])
        if index >len(self.long_url_list):
            return ""
        return self.long_url_list[index]


if __name__ == "__main__":
    url1 = "http://www.baidu.com"
    url2 = "http://www.google.com"
    url3 = "http://www.leetcode.com/faq/?id=10"

    s = Codec()

    short_url1 = s.encode(url1)
    short_url2 = s.encode(url2)
    short_url3 = s.encode(url3)
    print short_url1
    print short_url2
    print s.encode(url1)
    print short_url3

    print s.decode(short_url1)
    print s.decode(short_url2)
    print s.decode(short_url3)
